package com.sdry.untils;

import com.sdry.common.BaseAPIMessageTypeEnum;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.List;

/**
 * 
 * @ClassName ResponseUtil
 * @Description Response工具类
 * @Author lz
 * @Date 2018年9月10日 15:27:14
 * @Version 1.0
 */
public class ResponseUtil {

	public static void write(HttpServletResponse response,Object o)throws Exception{
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out=response.getWriter();
		if(o != null) {
			out.println(o.toString());
		}else {
			out.println("");
		}
		out.flush();
		out.close();
	}

	public static JSONObject jSONObjectAdd(JSONObject jsonObject,HttpServletRequest request){
		String token = request.getParameter("token");
		jsonObject.put("token", token);
		return jsonObject;
	}

	public static JSONObject SelectJSONObjectAdd(List<?> list,JSONObject jsonObject){
		if(list.size() > 0){
			jsonObject.put("status", "1");
			jsonObject.put("data", list);
		}else{
			jsonObject.put("status", "0");
			jsonObject.put("message", BaseAPIMessageTypeEnum.A001.getName());
		}
		return jsonObject;
	}
}
